//
//  MySpecialDisappearButton.cpp
//  CanYouDoIt
//
//  Created by hoangtx on 7/9/13.
//
//

#include "MySpecialDisappearButton.h"
#include "MyUtilities.h"

bool MySpecialDisappearButton::init(){
    return true;
}



MySpecialDisappearButton* MySpecialDisappearButton::create(const char *fileName, double mX, double mY, double mWidth, double mHeight){
    MySpecialDisappearButton* button = MySpecialDisappearButton::create();
    button->setPosition(ccp(mX,mY));
    button->buttonSize = CCSizeMake(mWidth, mHeight);
    button->sprite = CCSprite::create(fileName);
    button->sprite->setAnchorPoint(ccp(0.5,0.5));
    button->sprite->setScaleX(mWidth/button->sprite->getContentSize().width);
    button->sprite->setScaleY(mHeight/button->sprite->getContentSize().height);
    button->sprite->setPosition(ccp(mWidth/2,mHeight/2));
    button->addChild(button->sprite);
    return button;
}

void MySpecialDisappearButton::onTouchButton(){
    minimize();
}

void MySpecialDisappearButton::addCallbackAfterMinimize(cocos2d::CCCallFuncO *mCallback){
    callbackAfterMinimize = mCallback;
    callbackAfterMinimize->retain();
    
}

void MySpecialDisappearButton::minimize(){

    CCScaleTo* scaleAction = CCScaleTo::create(0.1f, 0);
    CCCallFuncO* callback = CCCallFuncO::create(this, callfuncO_selector(MySpecialDisappearButton::didFinishMinimize), sprite);
    sprite->runAction(CCSequence::create(scaleAction,callback,NULL));
}
void MySpecialDisappearButton::didFinishMinimize(cocos2d::CCObject *sender){
    this->runAction(CCSequence::create(callbackAfterMinimize,NULL));
}

bool MySpecialDisappearButton::isTouchedAt(cocos2d::CCPoint touchPosition){
    return getBoundingRect().containsPoint(touchPosition);
}